package getOffer;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: wjy
 * @Date: 2021/11/22 11:17
 */
public class Practice14 {

    public static void main(String[] args) throws IllegalAccessException, ClassNotFoundException, InstantiationException {

/*        Practice15 practice15 = new Practice15();
        Field[] declaredFields = practice15.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            System.out.println(field.getType());
            System.out.println(field.getName());
        }*/



        Object o = Class.forName("getOffer.Practice15").newInstance();
        Field[] declaredFields = o.getClass().getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            String fieldType = field.getType().getName().substring(field.getType().getName().lastIndexOf(".") + 1, field.getType().getName().length());

            switch (fieldType) {
                case "String":
                    field.set(o, "123");
                    break;
                case "Integer":
                    field.set(o, 123);
                    break;
                default:
                    break;
            }
            //String fieldType = field.getType().getName();
            //System.out.println(fieldType);
            System.out.println(field.getName());
            System.out.println(field.get(o));
        }

    }

    public void setClass() {

    }

}
